#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
using namespace std;
class Solution {
public:
    void nextPermutation(vector<int>& nums) {
        if (nums.size() <= 1)return;
        int i, j, min;
        for (i = nums.size() - 2; i >= 0; i--)
        {
            if (nums[i] < nums[i + 1])break;
        }
        if (i == -1)
        {
            sort(nums.begin(), nums.end());
            return;
        }
        min = i+1;
        for (j = i + 2; j < nums.size(); j++)
        {
            if (nums[j]<nums[min] && nums[j]>nums[i])
            {
                min = j;
            }
        }
        j = nums[i];
        nums[i] = nums[min];
        nums[min] = j;
        sort(nums.begin()+i+1, nums.end());
        return;
    }
};
int main()
{
	Solution sol;
}